﻿// Copyright (c) Microsoft Corporation
//
// All rights reserved. 
//
// Licensed under the Apache License, Version 2.0 (the ""License""); you may not use this file 
// except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING 
// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY 
// OR NON-INFRINGEMENT. 
//
// See the Apache Version 2.0 License for specific language governing permissions and limitations under the License.

using System;
using System.Net.Http;
using Microsoft.WindowsAzure.MobileServices;
using TED.WindowsAzure.Unplugged.Mobile.Folder;
using TED.WindowsAzure.Unplugged.Mobile.Interfaces;
using TED.WindowsAzure.Unplugged.Mobile.Storage;
using TED.WindowsAzure.Unplugged.Mobile.Sync.Context;

namespace TED.WindowsAzure.Unplugged.Mobile
{
    /// <summary>
    /// Starting point for the API. Create an instance of this class to get thecontext and create remote folders
    /// </summary>
    public class UnpluggedMobileServiceClient : MobileServiceClient, IUnpluggedMobileServiceClient
    {
        public UnpluggedMobileServiceClient(Uri applicationUri, string applicationKey,
            params HttpMessageHandler[] handlers) : base(applicationUri, applicationKey, handlers)
        {
            SyncContext = new SyncContext(this);
        }

        /// <summary>
        ///     The SyncContext is initialized with a local data store, the client will
        ///     return local sync-enabled tables by default.
        /// </summary>
        public ISyncContext SyncContext { get; private set; }

        /// <summary>
        /// Returns a reference to the RemoteFolder designated by folderName. The service called may have different 
        /// behavior if the folder doesn't yet exist on the remote site and could respond with different error messages
        /// depending on the implementation
        /// </summary>
        /// <param name="remoteStorage"></param>
        /// <param name="folderName"></param>
        /// <returns></returns>
        public RemoteFolder GetFolder(IRemoteFileStorage remoteStorage, string folderName)
        {
            return new RemoteFolder(remoteStorage, folderName);
        }
    }
}